package demo.InterfaceDamo;

/**
 * 实现类，打印全部学生信息（包含男女人数），打印全部学生平均分（去掉最高分和最低分）。
 * <p>
 * Version: 1.0
 * Author: 瓶子
 */
public class StudentsDateInterImpl2 implements StudentDateInter {
    private final Student[] students;

    public StudentsDateInterImpl2( Student[] students ) {
        this.students = students;
    }

    @Override
    public void printAllStudentsInfos() {
        int man = 0;
        int woman = 0;
        for ( int i = 0; i < students.length; i++ ) {
            Student student = students[i];
            System.out.println("学生姓名：" + student.getName() +
                                       "  学生性别：" + student.getSex() +
                                       "  学生成绩：" + student.getScore());
            if (student.getSex() == '男') {
                man++;
            } else {
                woman++;
            }
        }
        System.out.println("女学生共计：" + woman + "人 " + "男学生共计：" + man + "人");
    }

    @Override
    public void printAverageScore() {
        Student student = students[0];
        double maxScore = student.getScore();
        double minScore = student.getScore();
        double sumscore = student.getScore();
        for ( int i = 1; i < students.length; i++ ) {
            sumscore += students[i].getScore();

            if (maxScore < students[i].getScore()) {
                maxScore = students[i].getScore();
            }
            if (minScore > students[i].getScore()) {
                minScore = students[i].getScore();
            }
        }
        System.out.println("学生平均分为：" + sumscore / students.length);
        System.out.println("学生最高分为：" + maxScore);
        System.out.println("学生最低分为：" + minScore);


    }
}
